package com.zyz.O_网络编程.TCP.practice;

import java.io.*;
import java.net.Socket;

/**
 * @author: vick
 * @Date: 2025/4/15
 * @Description:
 * @version: 1.0
 */
public class Client {
    public static void main(String[] args) {
        String address = "192.168.0.106";
        int port = 8888;
        String filePath = "C:\\Users\\14338\\Desktop\\工作.txt";
        Socket socket = null;
        try {
            //1. 创建Socket对象，连接服务器
            socket = new Socket(address, port);
            BufferedReader bufferedReader = new BufferedReader(new FileReader(new File(filePath)));

            OutputStream outputStream = socket.getOutputStream();
            PrintStream printStream = new PrintStream(outputStream);
            //读取文件
            String len;
            while ((len = bufferedReader.readLine()) != null) {
                //发送给服务端端
                printStream.println(len);
            }
            System.out.println("文件发送成功");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
            try {
                socket.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
